import { BaseController, CoolController } from "@cool-midway/core";
import { Inject, Get, Query, Param } from "@midwayjs/core";
import { CityInfoService } from "../../service/info";
import { CityInfoEntity } from "../../entity/info";


@CoolController({
    api: ['list', 'page', 'info'],
    entity: CityInfoEntity,
    service: CityInfoService,
})
export class OpenCityInfoController extends BaseController {
    @Inject()
    cityInfoService: CityInfoService;

    /**
     * 获取城市列表
     * @param parentId 父级ID
     * @returns 城市列表
     */
    @Get('/list/parentId/:parentId', { summary: '根据父级ID获取城市列表' })
    async listByParentId(@Param('parentId') parentId: number) {
        return this.ok(await this.cityInfoService.getCityListByParentId(parentId));
    }

    /**
     * 获取城市列表
     * @param firstLetter 首字母
     * @returns 城市列表
     */
    @Get('/list/firstLetter/:firstLetter', { summary: '根据首字母获取城市列表' })
    async listByFirstLetter(@Param('firstLetter') firstLetter: string) {
        return this.ok(await this.cityInfoService.getCityListByFirstLetter(firstLetter));
    }

    /**
     * 获取城市列表
     * @param pinyin 拼音
     * @returns 城市列表
     */
    @Get('/list/pinyin/:pinyin', { summary: '根据拼音获取城市列表' })
    async listByPinyin(@Param('pinyin') pinyin: string) {
        return this.ok(await this.cityInfoService.getCityListByPinyin(pinyin));
    }

}